package objectstream;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : ObjectInputStreamDemo
 * @Author : 54061
 * @Date: 2022/2/14 17:52
 */

    /*
    EOFException : End Of File
 */
    public class ObjectInputStreamDemo {
        public static void main(String[] args) throws IOException, ClassNotFoundException {
            ObjectInputStream ois = new ObjectInputStream(
                    new FileInputStream("T_Day18\\aaa\\obj.txt"));

            //写一次 读一次 这一个对象一定是集合对象
            ArrayList list = (ArrayList) ois.readObject();
            //遍历集合
            for (Object o : list) {
                System.out.println("o = " + o);
            }

            ois.close();
        }

        public static void method1(ObjectInputStream ois) {
            //循环
            while(true){
                try {
                    Object o = ois.readObject();
                    System.out.println("o = " + o);
                } catch (Exception e) {
                    //System.out.println("对象已经全部取出!");
                    break;
                }
            }
        }

        public static void method(ObjectInputStream ois) throws IOException, ClassNotFoundException {
            //读对象
            Object o = ois.readObject();
            System.out.println("o = " + o);//100

            o = ois.readObject();
            System.out.println("o = " + o);//你好

            o = ois.readObject();
            System.out.println("o = " + o);//时间对象

            o = ois.readObject();
            System.out.println("o = " + o);//学生对象

            System.out.println( ois.readObject());//null
            System.out.println( ois.readObject());
            System.out.println( ois.readObject());
            System.out.println( ois.readObject());
            System.out.println( ois.readObject());
        }
}
